module Pan
  
  class Res
    
    def initialize(mongrel_response)
      @res = mongrel_response
    end
    
    def close
      @res.socket.close
    end

    def header
      @res.header
    end
    
    def body
      @res.body
    end
    
    def not_rendered?
      body.size == 0
    end
    
    def start(status,&block)
      @res.start(status,true,&block)
      close
    end
    
    def redirect_302(location)
      start(302) do |head,out|
        head["Location"] = location
      end
    end

    def redirect_303(location)
      start(303) do |head,out|
        head["Location"] = location
      end
    end
    
    def html_response(html)
      start(200) do |head,out|
        head["Content-Type"] = "text/html"
        out.write(html)
      end
    end
  end
  
end
